﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OOAD_Project_Engine.Domain.Entities;
using OOAD_Project_Engine.Domain.Components;
using OOAD_Project_Engine.Foundation.MyEventArgs;

namespace OOAD_Project_Editor.Presentation
{
    public partial class EntityForm : Form
    {
        public List<Entity> EntityTempletes { get; set; }
        private Entity SelectEntity { get; set; }
        public EventHandler<EntityEventArgs> OnAddingEntity;


        public EntityForm()
        {
            InitializeComponent();
            EntityTempletes = new List<Entity>();
            EntityTempletes.Add(new Entity("NewEntity"));
            EntityTempletes.Add(new Entity("TestEntity", new Transform()));
            updateList();
        }

        private void updateList()
        {
            foreach (Entity t in EntityTempletes)
            {
                ListViewItem item = new ListViewItem(t.Name, 0);
                item.Tag = t;
                listView1.Items.Add(item);
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if ((int)msg.LParam == 0x203e0001)   // Alt-F4
            {
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (ListViewItem item in listView1.SelectedItems) //多選會是最後一個
            {
                SelectEntity = item.Tag as Entity;
            }
        }

        private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (OnAddingEntity != null)
                OnAddingEntity(this, new EntityEventArgs(SelectEntity));
        }
    }
}
